﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="DHGMS Solutions" file="EventLog.cs">
//   2004-2012 DHGMS Solutions. Some Rights Reserved. Licensed under GNU General Public License version 2 (GPLv2)
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Dhgms.TplHelper.Model.Provider.Job
{
    using System;
    using System.Collections.Specialized;
    using System.Diagnostics;

    using Dhgms.TplHelper.Model.Info.JobResult;

    /// <summary>
    /// Handles job reporting to the Event Log
    /// </summary>
    /// <typeparam name="TJobResultClass">
    /// </typeparam>
    internal class EventLog<TJobResultClass> : Base<TJobResultClass>
        where TJobResultClass : Base, new()
    {
        #region Public Methods and Operators

        /// <summary>
        /// Handles sending of error information to different mediums
        /// </summary>
        /// <param name="programGuid">
        /// Unique GUID used to identify program
        /// </param>
        /// <param name="programName">
        /// Friendly name of program
        /// </param>
        /// <param name="e">
        /// Exception message
        /// </param>
        public override void OnJobFailure(Guid programGuid, string programName, Exception e)
        {
            EventLog.WriteEntry(programGuid.ToString(), "The job failed:\r\n" + e, EventLogEntryType.Error, 1);
        }

        /// <summary>
        /// Notify the provider of a job start
        /// </summary>
        /// <param name="jobGuid">
        /// Unique ID of the job
        /// </param>
        public override void OnJobStart(Guid jobGuid)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Handles sending out the result information
        /// </summary>
        /// <param name="jobGuid">
        /// Unique GUID used to identify program
        /// </param>
        /// <param name="jobName">
        /// Friendly name of program
        /// </param>
        /// <param name="taskResult">
        /// Run results of task
        /// </param>
        public override void OnJobSucess(Guid jobGuid, string jobName, TJobResultClass taskResult)
        {
            EventLog.WriteEntry(jobGuid.ToString(), "The job suceeded.", EventLogEntryType.Information, 1);
        }

        /// <summary>
        /// Handles the sending of a task failure notification, if required
        /// </summary>
        /// <param name="taskGuid">
        /// The GUID relating to the task
        /// </param>
        /// <param name="e">
        /// Exception message
        /// </param>
        public override void OnTaskFailure(Guid taskGuid, Exception e)
        {
        }

        /// <summary>
        /// Handles the sending of a task start notification, if required
        /// </summary>
        /// <param name="taskGuid">
        /// The GUID relating to the task
        /// </param>
        public override void OnTaskStart(Guid taskGuid)
        {
        }

        /// <summary>
        /// Handles the sending of a task completion notification, if required
        /// </summary>
        /// <param name="taskGuid">
        /// The GUID relating to the task
        /// </param>
        public override void OnTaskSucess(Guid taskGuid)
        {
        }

        #endregion

        #region Methods

        /// <summary>
        /// On Initlize event
        /// </summary>
        /// <param name="name">
        /// </param>
        /// <param name="config">
        /// </param>
        protected override void OnInitialize(string name, NameValueCollection config)
        {
        }

        #endregion
    }
}